package org.gd.hellojaxb.privat24.version;

import org.gd.hellojaxb.adapters.DateAdaptersFactory;
import org.gd.hellojaxb.utils.MarshallProperties;
import org.gd.hellojaxb.utils.Marshall;

import javax.xml.bind.annotation.*;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
import java.util.Date;

@XmlRootElement(name = "version")
@XmlAccessorType(XmlAccessType.FIELD)
public class PVersion {

    @XmlAttribute(name = "buildDate")
    @XmlJavaTypeAdapter(DateAdaptersFactory.DateTimeFormat.class)
    public static final Date buildDate;
    @XmlAttribute(name = "buildNum")
    public static final String buildNumber;

    private static PVersion pVersion = null;

    static {
        buildDate = new Date();
        buildNumber = "1.0.10";
    }

    private PVersion() {
    }

    public static PVersion getInstance() {
        if(pVersion == null) {
            pVersion = new PVersion();
        }
        return pVersion;
    }

    @Override
    public String toString() {
        try {
            return Marshall.getInstance().marshal(this, MarshallProperties.WITHOUT_XML_HEADER);
        } catch (Exception e) {
            return super.toString();
        }
    }

    public static void main(String...args) {
        System.out.println(PVersion.getInstance().toString());
    }
}
